package com.platform.util;

import cn.hutool.core.codec.Base64;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.spec.AlgorithmParameterSpec;

public class WXUtils {

    @Autowired
    private static RestTemplate restTemplate;
	
	public static String getAccessToken() {
		
		
		return null;
	}

	public static String decrypt(String sessionkey, String ivdata, String encrypdata) throws Exception {
		byte[] encData = Base64.decode(encrypdata);
		byte[] iv = Base64.decode(ivdata);
		byte[] key = Base64.decode(sessionkey);
		AlgorithmParameterSpec ivSpec = new IvParameterSpec(iv);
		Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
		SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
		cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
		//解析解密后的字符串
		return new String(cipher.doFinal(encData),"UTF-8");
	}
	public static void main(String[] args) {
		getAccessToken();

	}

}
